home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / TimGA 1.2.1 / .cp / CProbDialog.cp < prev    next >
Encoding:
Text File  |  1997-07-16  |  4.4 KB  |  169 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    CProbDialog.cp            ©1995-97 Timo Eloranta        All rights reserved.
  3. // ===========================================================================
  4.  
  5. #include "CProbDialog.h"
  6. #include "GraphGA_PaneIDs.h"
  7.  
  8. #include <PP_Messages.h>
  9.  
  10. #include <LCaption.h>
  11. #include <LGAPushButton.h>
  12.  
  13. #include "CAGASlider.h"
  14.  
  15. // ---------------------------------------------------------------------------
  16. //        • CProbDialog
  17. //
  18. //          Called by:    URegistrar::CreateObject
  19. // ---------------------------------------------------------------------------
  20.  
  21. CProbDialog::CProbDialog( LStream *inStream )
  22.     : LGADialogBox( inStream )
  23. {
  24. }
  25.  
  26. // ---------------------------------------------------------------------------
  27. //        • InitDialog
  28. //
  29. //          Called by:    CGraphGAApp::ObeyCommand
  30. // ---------------------------------------------------------------------------
  31.  
  32. void
  33. CProbDialog::InitDialog()
  34. {
  35.     mCrossCapt        = (LCaption*) this -> FindPaneByID( capt_Crossover );
  36.     mMutaCapt        = (LCaption*) this -> FindPaneByID( capt_Mutation );
  37.     
  38.     mFactoryButton    = (LGAPushButton*) this -> FindPaneByID( but_FactorySettings);
  39.     
  40.     mCrossSlider    = (CAGASlider *) this -> FindPaneByID( slid_CrossSlider);
  41.     mMutaSlider        = (CAGASlider *) this -> FindPaneByID( slid_MutaSlider);
  42.  
  43.     if ( mFactoryButton) 
  44.         mFactoryButton -> AddListener( this );
  45.  
  46.     if ( mCrossSlider )
  47.         mCrossSlider -> AddListener( this );
  48.  
  49.     if ( mMutaSlider )
  50.         mMutaSlider -> AddListener( this );
  51. }
  52.  
  53. // ---------------------------------------------------------------------------
  54. //        • SetValues
  55. //
  56. //          Called by:    CGraphGAApp::ObeyCommand
  57. // ---------------------------------------------------------------------------
  58.  
  59. void
  60. CProbDialog::SetValues( Int32 inCrossValue, Int32 inMutaValue )
  61. {
  62.     if ( mCrossCapt )
  63.         mCrossCapt -> SetValue( inCrossValue );
  64.     if ( mCrossSlider )
  65.         mCrossSlider -> SetValue( inCrossValue );
  66.  
  67.     if ( mMutaCapt )
  68.         mMutaCapt -> SetValue( inMutaValue );
  69.     if ( mMutaSlider )
  70.         mMutaSlider -> SetValue( inMutaValue );
  71. }
  72.  
  73. // ---------------------------------------------------------------------------
  74. //        • GetValues
  75. //
  76. //          Called by:    CGraphGAApp::SetProbsFromDialog
  77. //                        CProbDialog::AdjustFactoryButton
  78. // ---------------------------------------------------------------------------
  79.  
  80. void
  81. CProbDialog::GetValues( Int32 &outCrossValue, Int32 &outMutaValue )
  82. {
  83.     if ( mCrossCapt )
  84.         outCrossValue = mCrossCapt -> GetValue();
  85.     if ( mMutaCapt )
  86.         outMutaValue = mMutaCapt -> GetValue();
  87. }
  88.  
  89. // ---------------------------------------------------------------------------
  90. //        • ListenToMessage
  91. //
  92. //          Called by:    LBroadcaster::BroadcastMessage
  93. // ---------------------------------------------------------------------------
  94.  
  95. void
  96. CProbDialog::ListenToMessage(
  97.     MessageT    inMessage, 
  98.     void        *ioParam )
  99. {
  100.     switch ( inMessage ) {
  101.         
  102.         case msg_CrossSlider:
  103.             if ( mCrossCapt ) {
  104.                 mCrossCapt -> SetValue( *(Int32 *) ioParam );
  105.                 mCrossCapt -> Draw(nil);
  106.                 AdjustFactoryButton();
  107.             }
  108.             break;
  109.  
  110.         case msg_MutaSlider:
  111.             if ( mMutaCapt ) {
  112.                 mMutaCapt -> SetValue( *(Int32 *) ioParam );
  113.                 mMutaCapt -> Draw(nil);
  114.                 AdjustFactoryButton();
  115.             }
  116.             break;
  117.             
  118.         case msg_FactorySettings:
  119.             SetValues( DEFAULT_CROSSOVER_PROB, DEFAULT_MUTATION_PROB );
  120.             break;
  121.             
  122.         default:    
  123.             LGADialogBox::ListenToMessage( inMessage, ioParam );
  124.             break;
  125.     }
  126. }
  127.  
  128. // ---------------------------------------------------------------------------
  129. //        • AdjustFactoryButton    (PRIVATE)
  130. //
  131. //          Called by:    CProbDialog::ListenToMessage
  132. // ---------------------------------------------------------------------------
  133.  
  134. void
  135. CProbDialog::AdjustFactoryButton( )
  136. {
  137.     Int32    theCrossValue, theMutaValue;
  138.     
  139.     GetValues( theCrossValue, theMutaValue );
  140.     
  141.     if ( theCrossValue == DEFAULT_CROSSOVER_PROB &&
  142.          theMutaValue == DEFAULT_MUTATION_PROB )
  143.              mFactoryButton -> Disable();
  144.     else
  145.         if ( ! mFactoryButton -> IsEnabled() ) 
  146.              mFactoryButton -> Enable();
  147. }
  148.  
  149. // ---------------------------------------------------------------------------
  150. //        • FindCommandStatus
  151. //
  152. //          Called by:    LCommander::ProcessCommandStatus
  153. // ---------------------------------------------------------------------------
  154. //    Disable all menu items except for the one which opens the About box.
  155.  
  156. void
  157. CProbDialog::FindCommandStatus(
  158.     CommandT    inCommand,
  159.     Boolean        &outEnabled,
  160.     Boolean&    /* outUsesMark */,
  161.     Char16&        /* outMark */,
  162.     Str255        /* outName */)
  163. {
  164.     outEnabled = false;
  165.     if (inCommand == cmd_About) {
  166.         outEnabled = true;
  167.     }
  168. }
  169.